package com.begye.smartloan.apptest.disclosure.adapter

import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.begye.smartloan.apptest.R
import org.json.JSONObject

class DisclosureIndicatorAdapter(var dataList: List<JSONObject>) :
    RecyclerView.Adapter<DisclosureIndicatorAdapter.ViewHolder>() {

    override fun onCreateViewHolder(
        parent: ViewGroup,
        viewType: Int,
    ): ViewHolder {
        val view = LayoutInflater.from(parent.context)
            .inflate(R.layout.list_item_disclosure_indicator, parent, false)
        return ViewHolder(view)
    }

    inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        private val listItemDisclosureIndicator: View =
            view.findViewById(R.id.listItemDisclosureIndicator)

        fun bindData(position: Int, item: JSONObject) {
            val isChecked = item.optBoolean("isChecked", false)
            if (isChecked) {
                listItemDisclosureIndicator.setBackgroundResource(R.drawable.layer_c5_000000)
            } else {
                listItemDisclosureIndicator.setBackgroundResource(R.drawable.layer_c5_dedede)
            }
        }
    }

    @SuppressLint("SetTextI18n")
    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.bindData(position, dataList[position])
    }

    override fun getItemCount(): Int {
        return dataList.size
    }
}